package online.hxstar.cloud.web.util;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * @author xinghu
 * @version 1.0
 * @date 2019/12/4 9:49 上午
 */
@Slf4j
public class EntityUtil {
	public static String ReadAsChars(HttpServletRequest request) {
		StringBuilder sb = new StringBuilder();
		try (InputStream inputStream = request.getInputStream();
		     BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
			//将获取到的请求参数重新塞入request里面去
			String line;
			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}
		} catch (IOException e) {
			log.error("获取requestBody", e);
		}
		return sb.toString();
	}
}
